export default {
    data() {
        return {};
    },
    // 距离计算
    getDistance(lat1, lng1, lat2, lng2) {
        // lat1用户的纬度 	 lng1用户的经度		lat2目标的纬度	lng2目标的经度
        let radLat1 = (lat1 * Math.PI) / 180.0;
        let radLat2 = (lat2 * Math.PI) / 180.0;
        let a = radLat1 - radLat2;
        let b = (lng1 * Math.PI) / 180.0 - (lng2 * Math.PI) / 180.0;
        let distance = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
        distance = distance * 6378.137;
        distance = Math.round(distance * 10000) / 10;
        return (distance = distance.toFixed(1));
    },
    problemType(type) {
        switch (type) {
            case 0:
                return '隔离栏';
                break;
            case 1:
                return '其他';
                break;
            case 2:
                return '护栏';
                break;
            case 3:
                return '桥梁';
                break;
            case 4:
                return '树围';
                break;
            case 5:
                return '井盖';
                break;
            case 6:
                return '沥青路面';
                break;
            case 7:
                return '道板';
                break;
            case 8:
                return '砼路面';
                break;
            case 9:
                return '石墩';
                break;
            case 10:
                return '缘石坡道';
                break;
            case 11:
                return '道路积水';
                break;
            case 12:
                return '花坛';
                break;
            case 12:
                return '道路开挖';
                break;
            default:
                break;
        }
    }
};
/**
 * 将服务端返回的 fields 字符串数组，解析成 JSON 数组
 * 如果指定了 variables 参数可对表单进行初始化
 *
 * @param fields JSON 字符串数组
 * @param variables Object 表单初始值
 * @returns {*[]} JSON 数组
 */
export function decodeFields(fields, variables) {
    const drawingList = (fields || []).map(json => {
      const item = JSON.parse(json)
  
      if (typeof variables === 'undefined' ) return item
  
      const setDefault = (item, variables) => {
        if (typeof variables[item.__vModel__] !== 'undefined') {
          item.__config__.defaultValue = variables[item.__vModel__]
        }
        if (item.__config__.children && item.__config__.children.length) {
          item.__config__.children.forEach(child => {
            setDefault(child, variables)
          })
        }
      }
  
      setDefault(item, variables)
  
      return item
    })
  
    return drawingList
  }
  /**
 * 将毫秒，转换成时间字符串。例如说，xx 分钟
 *
 * @param ms 毫秒
 * @returns {string} 字符串
 */
export function getDate(ms) {
    const day = Math.floor(ms / (24 * 60 * 60 * 1000));
    const hour =  Math.floor((ms / (60 * 60 * 1000) - day * 24));
    const minute =  Math.floor(((ms / (60 * 1000)) - day * 24 * 60 - hour * 60));
    const second =  Math.floor((ms / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - minute * 60));
    if (day > 0) {
      return day + "天" + hour + "小时" + minute + "分钟";
    }
    if (hour > 0) {
      return hour + "小时" + minute + "分钟";
    }
    if (minute > 0) {
      return minute + "分钟";
    }
    if (second > 0) {
      return second + "秒";
    } else {
      return 0 + "秒";
    }
  }